package com.cloudkinto.controller.options;

import com.cloudkinto.common.web.SingleResult;
import com.cloudkinto.enumType.common.CountryEnum;
import com.cloudkinto.enumType.common.TimeZoneEnum;
import com.cloudkinto.entity.ProvinceDo;
import com.cloudkinto.service.province.ProvinceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author long
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "字典(前端下拉选项)")
@RequestMapping("/api/admin/options")
public class OptionsController {

    private final ProvinceService provinceService;

    @ApiOperation(value = "查国家", notes = "查国家")
    @GetMapping("/country")
    public SingleResult<List<Map<String, String>>> country() {
        return SingleResult.success(
                CountryEnum.getCountryEnumList()
        );
    }

    @ApiOperation(value = "查时区", notes = "查时区")
    @GetMapping("/timeZone")
    public SingleResult<List<Map<String, Object>>> timeZone() {
        return SingleResult.success(
                TimeZoneEnum.getTimeZoneList()
        );
    }

    @ApiOperation(value = "查省份", notes = "查省份")
    @GetMapping("/province")
    public SingleResult<List<ProvinceDo>> province(@RequestParam(value = "countryRegionCode") String countryRegionCode) {
        return SingleResult.success(
                provinceService.lambdaQuery()
                        .eq(ProvinceDo::getCountryRegionCode, countryRegionCode.toUpperCase())
                        .list()
        );
    }

    @ApiOperation(value = "查币种", notes = "查币种")
    @GetMapping("/currency")
    public SingleResult<List<String>> currency() {
        return SingleResult.success(
                CountryEnum.getCurrencyList()
        );
    }

}
